from datetime import datetime

from pydantic import BaseModel, EmailStr, Field, field_validator


class UserBase(BaseModel):
    username: str
    email: EmailStr
    full_name: str | None = None
    created_time: datetime = Field(default_factory=datetime.now)

    @field_validator('created_time', mode='before')
    def validate_timestamp(cls, value):
        if isinstance(value, str):
            return datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
        return value

class UserCreate(UserBase):
    pass

class UserUpdate(UserBase):
    pass

class UserResponse(UserBase):
    id: int


# 定义job的Pydantic模型
class JobCreate(BaseModel):
    name: str
    task_function: str
    cron_expression: str | None = None
    interval_seconds: int | None = None
    job_args: list | None = None
    job_kwargs: dict | None = None

class JobUpdate(BaseModel):
    cron_expression: str | None = None
    interval_seconds: int | None = None
    is_active: bool | None = None
    name: str | None = None

class JobResponse(BaseModel):
    id: str
    name: str
    next_run_time: str |  None
    trigger: str
    is_active: bool |  None
    task_function: str | None
    created_time: str | None

